import request from '@/utils/request';

/**
 * 分页查询报关行
 */
export async function pageCustomBrokers(params) {
  const res = await request.get('/order/customBroker/page', { params });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询报关行列表
 */
export async function listCustomBrokers(params) {
  const res = await request.get('/order/customBroker', { params });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询报关行
 */
export async function getCustomBroker(id) {
  const res = await request.get('/order/customBroker/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加报关行
 */
export async function addCustomBroker(data) {
  const res = await request.post('/order/customBroker', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改报关行
 */
export async function updateCustomBroker(data) {
  const res = await request.put('/order/customBroker', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除报关行
 */
export async function removeCustomBroker(id) {
  const res = await request.delete('/order/customBroker/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 审核报关行
 */
export async function examCustomBroker(data) {
  const res = await request.post('/order/customBroker/examCustomBroker', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
